public class MDnewButtonOverride{

    public final String FIELD_CITY= 'MDCity__c';
    
    public MDnewButtonOverride(ApexPages.StandardController controller) {
        this.controller = controller;
    }
    public pagereference newnew(){
        List<place__c> city;
        id cityid;
        string name;
        Field_Info__c fieldid=[select Field_ID__c from Field_Info__c where name=: Field_city and SobjectType__c='marketdynamic__c'];
        id uid=userinfo.getuserid();
        List<user> cityname=[select id,usercity__c from user where id=:uid];
        if(cityname[0].usercity__c!=null){
            name=cityname[0].usercity__c.trim();
            city=[select id from place__c where PlaceType__c=:'City' and name=:name];
            if(city.size()>0){
                cityid=city[0].id;
            }
        }

        PageReference ref=null;
        ref=new PageReference('/a0o/e?retURL=%2Fa0o&nooverride=1');  
        ref.getParameters().put('CF'+fieldid.field_id__c,name);              //00NO0000000JokN :城市字段
        ref.getParameters().put('CF'+fieldid.field_id__c+'_lkid',cityid);        
  
        ref.setRedirect(true);
        return ref;
        
  }  
    private final ApexPages.StandardController controller;
    
    static testMethod void MDnewButtonOverrideTest()
    {
        Profile p  = [select id from profile where name = 'System Administrator'or name =: '系统管理员'];
        
        User u1 = new User (alias = 'standt', email = 'shuaicao@isoftstone.com', emailencodingkey='UTF-8', 
                lastname = 'Testing', languagelocalekey = 'en_US', localesidkey='en_US', Title__c = 'Sales Rep',profileid = p.id, 
                timezonesidkey = 'America/Los_Angeles', username='standarduser@testorg1.com');
        insert u1;
    
        marketdynamic__c add = new marketdynamic__c();
        
        insert add;
              
        test.setCurrentPageReference(Page.eventbuttonoverride);
        System.currentPageReference().getParameters().put('id', add.Id); 
        
        ApexPages.StandardController del = new ApexPages.StandardController(add);
        MDnewButtonOverride testCase = new MDnewButtonOverride(del);
        testCase.newnew(); 
    }     
    
    
    }